// pages/patrols/patrol_detail/patrol_detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollHeight: '64vh',
    data: "",
    address: '',
    start: '开始巡查',
    starttime: '',
    endtime: '',
    ok: true,
  },
  fnStartTap: function (e) {
    let index = e.currentTarget.dataset.index;
    let that = this;
    let time = new Date().toLocaleTimeString();
    if (index == '1') {
      if (that.data.ok) {
        that.setData({
          start: '巡查中',
          starttime: 'start:' + time
        })
      }
    }
    else {
      that.setData({
        start: '巡查结束',
        endtime: 'end:' + time
      })
    }
    that.data.ok = false;
  },
  fnCardTap: function (e) {
    let index = e.currentTarget.dataset.index;
    let that = this;
    wx.getLocation({
      success: (res) => {
        let address = that.data.address;
        address += '(' + res.latitude + ',' + res.longitude + ')' + '、';
        that.setData({
          address,
        })
      },
      fail: (res) => {
        console.log(res);
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let data = JSON.parse(options.data);
    let scrollHeight;
    if (data.state == '已结束' || data.state == '未开始') {
      scrollHeight = '92vh';
    } else {
      scrollHeight = '70vh';
    };
    this.setData({
      scrollHeight,
      data
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})